#include <linux/module.h>
#include <linux/fs.h>
#include <linux/debugfs.h>


struct dentry *kblock_debugfs_root;
struct dentry *kblock_debugfs_version;

int kblock_version_open(struct inode *inode,struct file *file);
int kblock_version_read(struct file *file,char __user *buf,size_t nbytes, loff_t *pos);
int kblock_version_write(struct file *file,const char __user *buf,size_t nbytes, loff_t *pos);
int kblock_version_release(struct inode *inode,struct file *file);

const struct file_operations kblock_version_fops = {
	.open = kblock_version_open,
	.read = kblock_version_read,
	.write = kblock_version_write,
	.release = kblock_version_release,
	.llseek = generic_file_llseek
};

int kblock_version_open(struct inode *inode,struct file *file)
{
    return 0;
}

int kblock_version_release(struct inode *inode,struct file *file)
{
    return 0;
}

int kblock_version_read(struct file *file,char __user *buf,size_t nbytes,loff_t *pos)
{
	char data[256] = {0};
    int ret = 0;
	ret = snprintf(data,256,"kblock:version 1.0.0.0\n");
	return simple_read_from_buffer(buf, nbytes, pos, data,ret);    
}

int kblock_version_write(struct file *file,const char __user *buf,size_t nbytes,loff_t *pos)
{
    return 0;
}

int register_kblock_debugfs(void)
{
    kblock_debugfs_root = debugfs_create_dir("kblock",NULL);
    if (kblock_debugfs_root == NULL) {
        return -1;
    }

    kblock_debugfs_version = debugfs_create_file("version",S_IFREG|S_IRUSR,kblock_debugfs_root,NULL,&kblock_version_fops);
    if (kblock_debugfs_version == NULL) { 
        return -1;
    }
	return 0;
}

int unregister_kblock_debugfs(void)
{
    debugfs_remove_recursive(kblock_debugfs_root);
	return 0;
}